package com.wzb.mybatisplus.bitaction.electrumaction.three;

import com.wzb.mybatisplus.bitaction.electrumaction.one.BlockchainBalanceChecker;
import com.wzb.mybatisplus.entity.Bituse;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class testMain {
    public static void main(String[] args) {


        List<String> list = new ArrayList<>();
        list.add("12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX");
        list.add("1HLoD9E4SDFFPDiYfNYnkBLQ85Y51J3Zb1");
        list.add("bc1qsq0fwqrdk50g5990mlfqh8znt9thy728djkk5h");
        Set<String> addressesSys = new HashSet<>();
        addressesSys.add("1");
        addressesSys.add("2");
        addressesSys.add("3");
        // 批量调用比特币
        String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
        for(;result==null;){
//                    Thread.sleep(1000);
//                    flag++;
//                    System.out.println("=======调用比特币地址返回空，走进死循环中了======="+flag);
            result = BlockchainBalanceChecker.getBalanceForAddresses(list);
        }
        JSONObject jsonResponse = new JSONObject(result);
        int z = 0;
        for(String address : list){
            JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
            Long maney = addressInfo.getLong("final_balance");
            long total_received = addressInfo.getLong("total_received");
            long jiaoyiliang = addressInfo.getLong("n_tx");
            if (maney > 0.0 || jiaoyiliang > 0.0 || total_received > 0.0) {
                System.out.println("=======金额======" + maney + "私钥：" + addressesSys);
//                conutsum++;
                Bituse bituse = new Bituse();
                List<String> listSys = new ArrayList<>();
                listSys.addAll(addressesSys);
                bituse.setWifsy(listSys.get(z));
                bituse.setMask(maney + "");
//                bituseMapper.insert(bituse);
                SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                sendEmailToQQ.sendEmail("2267457055@qq.com",listSys.get(z));

//                        if (maney > 0.0) {
//                            System.exit(1);
//                        }
//                fileUtils.writeFile( listSys.get(z)+"\n",path);
                z++;
            }

        }
//        addressesSys.clear();
//        addresses.clear();
    }
}
